package com.wframe.project.jnd.services.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.frame.database.JdataBean;
import com.frame.database.PageResult;
import com.wframe.project.jnd.dao.InformationDao;
import com.wframe.project.jnd.dao.UserDao;
import com.wframe.project.jnd.services.InformationService;

@Service
public class InformationServiceImpl implements InformationService{

	@Autowired
	InformationDao
			infoDao;
	@Autowired
	UserDao userDao;
	
	/**
	 * 查询文章信息及分页信息
	 */
	public PageResult queryInfos(JdataBean parms,int size,int pageno){
		PageResult pr=infoDao.queryInfos(parms, size, pageno);
		return pr;
	}

	public PageResult wxqueryInfos(JdataBean parms,int size,int pageno){
		PageResult pr = infoDao.wxqueryInfos(parms,size,pageno);
		return pr;
	}

	public PageResult queryEntrances(JdataBean parms,int size,int pageno){
		PageResult pr = infoDao.queryEntrances(parms,size,pageno);
		return  pr;
	}
	
	public JdataBean getInfo(String id){
		return infoDao.getInfo(id);
	}
	public JdataBean getInfoByCode(String code){
		JdataBean parms=new JdataBean();
		parms.put("code", code);
		PageResult pr=infoDao.queryInfos(parms, 1, 1);
		if(pr.getList().size()>0){
			Map data=(HashMap)pr.getList().get(0);
			Object[] keys=data.keySet().toArray();
			JdataBean bean=new JdataBean();
			for(Object key:keys)
				bean.put(key.toString(), data.get(key.toString()));
			return bean;
		}
		else return null;
	}
	public String getInfoCon(String id){
		return infoDao.getInfoContent(id);
	}
	/**
	 * 查询下属所有子栏目
	 */
	public List<JdataBean> queryChannels(JdataBean parms){
		return infoDao.queryChannel(parms);
	}
	
	public JdataBean getChannel(String code){
		return infoDao.getChannel(code);
	}

	/**
	 *
	 */
	public JdataBean getInfoContentNew (String id) {
		return infoDao.getInfoContentNew(id);
	}

	public PageResult getcontentList(JdataBean pamrs,int pagesize,int pageno){
		return infoDao.getcontentList(pamrs,pagesize,pageno);
	}


	/**
	 * 查询下属栏目
	 */
	public List<Map> querySubChannel(String code){
		return infoDao.querySubChannel(code);
	}
	
	public PageResult queryStationnews(String userid,String grade,int size,int pageno){
		return infoDao.queryStationnews(userid, grade, size, pageno);
	}
	public JdataBean getStationnews(String id){
		return infoDao.getStationnews(id);
	}
	public void setStationnewsRead(String userid){
		infoDao.setStationnewsRead(userid);
	}
	public int statNonews(String userid) throws Exception{
		JdataBean user=userDao.getUser(userid);
		return infoDao.statNonews(userid,user.getString("grade"));
	}

	@Override
	public List<JdataBean> getIssueByCode(String code) {
		return infoDao.getIssueByCode(code);
	}
	public List<JdataBean> getIssueCode (String code){
		return infoDao.getIssueCode(code);
	}
	public JdataBean queryStationnewsTotal(String userid, String grade) {
		return infoDao.queryStationnewsTotal(userid,grade);
	}
}
